# Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

cc_library(
    name = "tracing",
    hdrs = [
        "framework_tags.h",
        "tracing_ops.h",
        "tracing_ops_provider.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":framework_tags",
        ":tracing_ops",
        ":tracing_ops_provider",
    ],
)

cc_library(
    name = "framework_tags",
    hdrs = ["framework_tags.h"],
    deps = [
        "@com_github_opentracing_opentracing_cpp//:opentracing",
    ],
)

cc_library(
    name = "string_view_interop",
    hdrs = ["string_view_interop.h"],
    deps = [
        "@com_github_opentracing_opentracing_cpp//:opentracing",
    ],
)

cc_library(
    name = "tracing_ops_provider",
    srcs = ["tracing_ops_provider.cc"],
    hdrs = [
        "framework_tags.h",
        "tracing_ops_provider.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":framework_tags",
        "//flare/base:dependency_registry",
        "//flare/base:function",
        "//flare/base/net:endpoint",
        "@com_github_opentracing_opentracing_cpp//:opentracing",
    ],
)

cc_library(
    name = "tracing_ops",
    srcs = ["tracing_ops.cc"],
    hdrs = ["tracing_ops.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":tracing_ops_provider",
        "//flare/base:chrono",
        "//flare/base:exposed_var",
        "//flare/base:maybe_owning",
        "//flare/base:never_destroyed",
        "//flare/base:overloaded",
        "//flare/base:random",
        "//flare/base:string",
        "//flare/base/internal:cpu",
        "//flare/base/internal:dpc",
        "//flare/base/internal:test_prod",
        "//flare/base/thread:thread_cached",
        "//flare/rpc/internal:sampler",
        "@com_github_gflags_gflags//:gflags",
        "@com_github_opentracing_opentracing_cpp//:opentracing",
    ],
)

cc_test(
    name = "tracing_ops_test",
    srcs = ["tracing_ops_test.cc"],
    deps = [
        ":framework_tags",
        ":tracing_ops",
        "//flare/rpc/tracing:string_view_interop",
        "//flare/testing:main",
    ],
)

cc_test(
    name = "tracing_ops_benchmark",
    srcs = ["tracing_ops_benchmark.cc"],
    deps = [
        ":framework_tags",
        ":tracing_ops",
        "@com_github_google_benchmark//:benchmark_main",
    ],
)

cc_test(
    name = "integration_test",
    srcs = ["integration_test.cc"],
    deps = [
        ":tracing",
        "//flare/base:overloaded",
        "//flare/base/internal:cpu",
        "//flare/fiber",
        "//flare/rpc",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:endpoint",
        "//flare/testing:main",
        "//flare/testing:relay_service_proto_flare",
        "@com_github_gflags_gflags//:gflags",
        "@com_github_opentracing_opentracing_cpp//:opentracing",
    ],
)
